import time

from selenium.webdriver.common.by import By

from xinan_ui.proxy.base_page import PageHandle
from xinan_ui.proxy.phone_uilogin import PhoneLoginUi
from xinan_ui.tools.App_driver import AppDriver01
from xinan_ui.tools.read_yml_xn import ReadYaml
import logging
data_eles = ReadYaml('../config/xnapp.yml').read_yaml()['Fir_page']


class Fir01Page(PageHandle):
    def __init__(self,driver):
        self.driver=driver
        super().__init__(self.driver)

    def go_fir_page(self):
        self.click_button(data_eles[0]['loc01'])

        self.click_button(data_eles[1]['loc02'])
        self.click_button(data_eles[2]['loc03'])
        time.sleep(5)
        try:
            self.click_button(data_eles[3]['loc04'])
        except:
            print("没出现弹窗")

        # time.sleep(3)
        # self.click_button(data_eles[4]['loc05'])
        # time.sleep(3)
        try:
            self.click_button(data_eles[5]['上海深圳主板风险提示'])
        except:
            print('没有出现上海深圳主板风险提示')
            logging.info('没有出现上海深圳主板风险提示')
        time.sleep(3)
        try:
            self.click_button(data_eles[6]['新股新债申购提示'])
        except:
            print('没出现新股新债申购提示弹窗')
            logging.info('没出现新股新债申购提示弹窗')
        time.sleep(3)
        self.click_button(data_eles[7]['loc07'])
        logging.info("进入首页")

if __name__ == '__main__':
    device_data=ReadYaml('../config/devices.yml').read_yaml()['yeshen']
    driver=AppDriver01().get_driver(desired_caps=device_data)

    F1=Fir01Page(driver)
    F1.x.driver=driver
    F1.go_fir_page()
    l=PhoneLoginUi(driver).phone_login('15680036769')

